<?php

class RL_FileSystem_DirectoryIterator implements Iterator
{
	public function __construct ($fso)
	{
		$this->dir = $fso;
		$this->rewind();
	} // end of __construct

	public function current ()
	{
		return $this->fso;
	} // end of function current

	public function key ()
	{
		return $this->key;
	} // end of function key

	public function next ()
	{
		$entry = readdir($this->dh);
		if ($entry === FALSE) {
			unset($this->dh);
			unset($this->key);
			unset($this->fso);
		} else {
			$this->fso = $this->dir[$entry];
			$this->key = $entry;
		}
		return $this->fso;
	} // end of function next

	public function rewind ()
	{
		$this->dh = opendir($this->dir->getPath());
	} // end of function rewind

	public function stop ()
	{
		closedir($this->dh);
		return;
	} // end of function stop
	public function valid ()
	{
		return isset($this->dh);
	} // end of function valid
}

